package service;

import java.util.ArrayList;
import java.util.HashMap;

import util.Utilities;
import dao.MessageDAO;
import dto.MemberDTO;
import dto.MessageDTO;

public class MessageManagerService {
	private MessageDAO dao;
	public MessageManagerService(MessageDAO dao) {
		this.dao = dao;
	}
	public void registerMessage(MessageDTO mto) {
		String writeDate =  Utilities.getNow();
		mto.setMsg_date(writeDate);
		dao.insertMessage(mto);	
		mto.setMsg_date(Utilities.changeDayTimeFormat(writeDate));
	}
	public ArrayList getAllMessageList(HashMap map) {
		
		ArrayList<MessageDTO> list = dao.selectAllMessage(map);
		for(MessageDTO mto : list) {
			mto.setMsg_date(Utilities.changeDayTimeFormat(mto.getMsg_date()));
		}
		return list;
	}
	public ArrayList getWriterMessageById(String member_id) {
		ArrayList<MessageDTO> list = dao.selectWriterMessageById(member_id);
		for(MessageDTO mto : list) {
			mto.setMsg_date(Utilities.changeDayTimeFormat(mto.getMsg_date()));
		}
		return list;
	}
	public ArrayList getReaderMessageById(String member_id) {
		ArrayList<MessageDTO> list = dao.selectReaderMessageById(member_id);
		for(MessageDTO mto : list) {
			mto.setMsg_date(Utilities.changeDayTimeFormat(mto.getMsg_date()));
		}
		return list;
	}
	public MemberDTO getWriterNameByMemberId(String member_id) {
		return dao.selectWriterNameByMemberId(member_id);
	}

	public ArrayList getSpecficMessageWAR(HashMap map) {
		ArrayList<MessageDTO> list = dao.selectSpecificMessageWAR(map);
		for(MessageDTO mto : list) {
			mto.setMsg_date(Utilities.changeDayTimeFormat(mto.getMsg_date()));		
		}
		return list;
	}
	public MemberDTO getMemberInfoByRoomNo(int room_no) {
		return dao.selectMemberInfoByRoomNo(room_no);
	}
	
	public MemberDTO getMemberIdByName(HashMap map) {
		return dao.selectMemberIdByName(map);
	}

	
	
}
